/*
   Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
   Original sources are available at www.latestbit.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#ifndef MODULEIMPL_HPP
#define MODULEIMPL_HPP

#include <map>
#include <boost/thread/mutex.hpp>
#include "cpputils/CppUtils.hpp"
#include "cpputils/dynmod/IModule.hpp"
#include "cpputils/dynmod/ModulesFactory.hpp"

namespace cpputils {
	namespace dynmod {
		/**
		 * Standard implementation of IModule interface
		 */
		class ModuleImpl : public IModule {
			ModulesFactory* m_poFactory;
			std::string m_sName;
			PtrDynmodInitFunc m_pfInitFunc;
			PtrDynmodFinalizeFunc m_pfFinFunc;
			PtrDynmodCreateInstanceFunc m_pfCreateInstanceFunc;

			unsigned int m_nReferenceCount;
			dlhandle_t m_hModule;
		protected:
			virtual void* createModuleObjectInstance(const std::type_info& oTypeInfo);
			virtual void addRef();
			virtual bool unload();
		public:
			ModuleImpl (
					const std::string& sName,
					ModulesFactory* poFactory,
					PtrDynmodInitFunc pfInitFunc,
					PtrDynmodFinalizeFunc pfFinFunc,
					PtrDynmodCreateInstanceFunc pfCreateInstanceFunc,
					dlhandle_t hModule
			);
			virtual ~ModuleImpl();
			virtual std::string getName();

		};
	}
}

#endif // MODULEIMPL_HPP
